package com.yikome.order.entity;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;

import org.springframework.data.annotation.LastModifiedDate;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@Entity
@Table(name = "o_order", indexes = {@Index(columnList = "code") , @Index(columnList = "deliveryCode") , @Index(columnList = "storehouseId")} , uniqueConstraints = {@UniqueConstraint(columnNames = {"deliveryCode" , "yn"})})
public class Order implements Serializable {

	private static final long serialVersionUID = 5535553915504212159L;

	private String code ; 
	
	private Integer payment ; 
	
	private BigDecimal price ; 
	
	private BigDecimal freight ;  
	
	private String remark ; 
	
	private Integer status ; 
	
	private String currency ; 
	
	private Integer priority ; 
	
	private String consignee ; 
	
	private String tel ; 
	
	private String contry ; 
	
	private String province ; 
	
	private String city ; 
	
	private String district ; 
	
	private String details ;
	
	private String zipCode ;
	
	private String email ;
	
	@Column(length=50)
	private String deliveryCode ;
	
	private Long storehouseId ; 
	
	private String affiliate ; 
	
	
	private String source ; 
	
	
	@Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;

    @LastModifiedDate
    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss z", locale = "zh", timezone = "GMT+8")
    private Date updatedAt;

    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss z", locale = "zh", timezone = "GMT+8")
    private Date createdAt;

    @JsonIgnore
    private Integer yn;

    @PrePersist
    private void prePersist() {
        if (this.yn == null) {
            this.yn = 1;
        }
    }


    @PreUpdate
    private void preUpdate() {
        if (this.yn == null) {
            this.yn = 1;
        }
    }
}
